package com.hzw.saas.web.admin.config;

import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * <p>
 *
 * </p>
 *
 * @author sonam
 * @since 2021/5/7 13:58
 */
@EnableAsync
@Configuration
public class ThreadPoolConfig {

    @Bean
    public Executor executor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();

        executor.setCorePoolSize(10);//配置核心线程数
        executor.setMaxPoolSize(15);//配置最大线程数
        executor.setQueueCapacity(50);
        executor.setThreadNamePrefix("thread-pool-service-");//线程的名称前缀
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        executor.initialize();

        return executor;
    }

}
